﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;

namespace useipboxshiyan
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void ConnectionTest_Click(object sender, EventArgs e)
        {
            textBox1.Text = ipBox1.GetIpAddress();
            // string ConnectionString = "Data Source="+servicesid.Text+";Persist Security Info=True;User ID="+UserID.Text+";Password="+Password.Text+";";
            
            string ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST =" + ipBox1.GetIpAddress() + ")(PORT =1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)));Persist Security Info=True;User ID=viot;Password=viot;";
            // OracleConnection conn = new OracleConnection("Data  Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.12.204)(PORT = 1521)))(CONNECT_DATA =(SERVICE_NAME = orcl)));User ID=viot;Password=viot;");
            bool IsCanConnectioned = false;
            OracleConnection conn = new OracleConnection(ConnectionString);
            try
            {
                conn.Open();
                IsCanConnectioned = true;
            }
            catch
            {
                IsCanConnectioned = false;
            }
            finally
            {
                conn.Close();
            }
            if (IsCanConnectioned)
            {
                MessageBox.Show("连接成功");
            }
            else
            {
                MessageBox.Show("连接不成功");
            }
        }
    }
}
